﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:Renci.iRods.Studio.Modules.Explorer.ViewModels"
    xmlns:vw="clr-namespace:Renci.iRods.Studio.Modules.Explorer.Views"
    xmlns:common="clr-namespace:Renci.iRods.Studio.Common;assembly=Renci.iRods.Studio.Common"
    xmlns:controls="clr-namespace:Renci.iRods.Studio.Modules.Explorer.Controls">

    <DataTemplate DataType="{x:Type common:MenuItem}">
        
        <MenuItem Header="{Binding Text}" ItemsSource="{Binding Children}" Command="{Binding Command}"/>
    </DataTemplate>
    
    <Style x:Key="ContextMenuItemStyle">
        <Setter Property="MenuItem.Header" Value="{Binding Text}"/>
        <Setter Property="MenuItem.ItemsSource" Value="{Binding Children}"/>
        <Setter Property="MenuItem.Command" Value="{Binding Command}" />
    </Style>

    <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Width" Value="19"/>
        <Setter Property="Height" Value="13"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Border Background="#00FFFFFF" Width="19" Height="13">
                        <Border BorderThickness="1,1,1,1" CornerRadius="1,1,1,1" BorderBrush="#FF7898B5" Width="9" Height="9" SnapsToDevicePixels="True">
                            <Border.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                    <LinearGradientBrush.GradientStops>
                                        <GradientStop Color="#FFFFFFFF" Offset="0.2" />
                                        <GradientStop Color="#FFC0B7A6" Offset="1" />
                                    </LinearGradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Border.Background>
                            <Path Data="M0,2L0,3 2,3 2,5 3,5 3,3 5,3 5,2 3,2 3,0 2,0 2,2z" Fill="#FF000000" Name="ExpandPath" Margin="1,1,1,1" />
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ToggleButton.IsChecked" Value="True">
                            <Setter Property="Path.Data" TargetName="ExpandPath">
                                <Setter.Value>
                                    <StreamGeometry>M0,2L0,3 5,3 5,2z</StreamGeometry>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <controls:LevelToIndentConverter x:Key="LevelToIndentConverter"/>
    
    <controls:CanExpandConverter x:Key="CanExpandConverter"/>

    <Style TargetType="{x:Type controls:TreeListViewRowExpander}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:TreeListViewRowExpander}">
                    <ToggleButton x:Name="Expander" 
									  Style="{StaticResource ExpandCollapseToggleStyle}" 
									  Margin="{Binding Node.Level, Converter={StaticResource LevelToIndentConverter},RelativeSource={RelativeSource AncestorType={x:Type controls:TreeListViewItem}}}"
									  IsChecked="{Binding Node.IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type controls:TreeListViewItem}}}"
									  Visibility="{Binding Node.IsExpandable, Converter={StaticResource CanExpandConverter},RelativeSource={RelativeSource AncestorType={x:Type controls:TreeListViewItem}}}"
									  ClickMode="Press"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
